package com.caesi.tacacaesifinal;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.caesi.tacacaesifinal.model.Campeonato;

public class CampeonatoAdapter extends BaseAdapter {

    private LayoutInflater mInflater;

    private List<Campeonato> listaCampeonatos;
    
    private View selectedView;

    private int lastPosition = -1;

    public CampeonatoAdapter(Context contexto, ArrayList<Campeonato> itens) {
        this.listaCampeonatos = itens;
        mInflater = LayoutInflater.from(contexto);

    }

    @Override
    public int getCount() {

        return listaCampeonatos.size();
    }

    @Override
    public Object getItem(int arg0) {

        return listaCampeonatos.get(arg0);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Pega o item de acordo com a posção.
        Campeonato item = listaCampeonatos.get(position);
        // infla o layout para podermos preencher os dados
        convertView = mInflater.inflate(R.layout.item_campeonato, null);

        // atravez do layout pego pelo LayoutInflater, pegamos cada id
        // relacionado
        // ao item e definimos as informações.
        ((TextView) convertView.findViewById(R.id.nome))
                .setText(item.getNome());
        ((TextView) convertView.findViewById(R.id.local)).setText(item
                .getLocal());
        ((ImageView) convertView.findViewById(R.id.imagemview))
                .setImageResource(R.drawable.bola);

        return convertView;

    }
    
    public void setSelectedView(View selectedView, int position) {
		this.lastPosition = position;
		if (this.selectedView != null) {
			this.selectedView.setBackgroundColor(Color.BLACK);
		}
		this.selectedView = selectedView;
		this.selectedView.setBackgroundResource(R.drawable.row_list);
	//	this.selectedView.setBackgroundColor(Color.argb(50, 135, 206, 255));
	}

}
